Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Fix cursor jump issue during list text editing #10181

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Jan 21, 2025

Checklist

General

Client

Motivation and Context

When editing text in a list (unordered or ordered) within a message, the text cursor would previously jump to the end of the line after each character addition. (Closes #10133)

Description

The cursor now maintains its position during text modifications, allowing seamless editing. The fix involved introducing a return; condition to prevent unnecessary processing when no text is selected, and the cursor is within the current line.

Steps for Testing

Prerequisites:

  • 1 User
  • 1 Course with Communication enabled
  1. Log in to Artemis
  2. Navigate to Communication section of a course
  3. Insert a list (unordered or ordered), write some text in the message input
  4. Go to the middle of the text and start writing or deleting some characters
  5. Verify correct cursor behavior

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
list.action.ts 80.68% ✅ ❌

Summary by CodeRabbit

  • Bug Fixes

    • Improved list action handling in the markdown editor to preserve cursor position when editing list items
    • Enhanced list prefix detection for more robust markdown formatting
  • Tests

    • Added test case to verify cursor position stability during list item editing

@asliayk asliayk added tests client Pull requests that update TypeScript code. (Added Automatically!) small bugfix component:Communication labels Jan 21, 2025
@asliayk asliayk self-assigned this Jan 21, 2025
@asliayk asliayk temporarily deployed to artemis-test5.artemis.cit.tum.de January 21, 2025 02:03 — with GitHub Actions Inactive
@asliayk asliayk marked this pull request as ready for review January 21, 2025 02:09
@asliayk asliayk requested a review from a team as a code owner January 21, 2025 02:09
Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request addresses an issue with text cursor positioning when editing list items in a markdown editor. The changes involve modifying the ListAction class in the Monaco editor to prevent the cursor from jumping to the end of the line during text editing. A corresponding test case has been added to verify the cursor position remains intact when performing list-related actions.

Changes

File Change Summary
src/main/webapp/app/shared/monaco-editor/model/actions/list.action.ts - Changed position declaration from let to const
- Added early return condition for specific cursor scenarios
- Slightly modified regex for list prefix detection
src/test/javascript/spec/component/shared/metis/postings-markdown-editor/postings-markdown-editor.component.spec.ts - Added new test case to verify cursor position preservation during list item editing

Assessment against linked issues

Objective Addressed Explanation
Prevent cursor jumping to end of line when editing list text [#10133]
Maintain cursor position during list item modifications

Possibly related PRs

Suggested labels

ready to merge

Suggested reviewers

  • HawKhiem
  • SimonEntholzer
  • sachmii
  • florian-glombik
  • az108

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1543e3e and 0453d9b.

📒 Files selected for processing (2)
  • src/main/webapp/app/shared/monaco-editor/model/actions/list.action.ts (1 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-markdown-editor/postings-markdown-editor.component.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/shared/monaco-editor/model/actions/list.action.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/shared/metis/postings-markdown-editor/postings-markdown-editor.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
src/main/webapp/app/shared/monaco-editor/model/actions/list.action.ts (1)

82-87: LGTM! The cursor position fix looks good.

The changes effectively prevent the cursor from jumping to the end of the line during text editing by adding an early return condition when no text is selected and the cursor is within the line length.

src/test/javascript/spec/component/shared/metis/postings-markdown-editor/postings-markdown-editor.component.spec.ts (1)

586-606: LGTM! Comprehensive test coverage for cursor position fix.

The test case thoroughly verifies that:

  1. The cursor position remains intact during list text editing
  2. No unnecessary text replacements occur
  3. The cursor stays at the correct column position
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@anian03 anian03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6, did not notice any issues with the cursor position

Copy link

@eylulnc eylulnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in TS6, testing session. Work as expected ✅

Copy link
Contributor

@FelberMartin FelberMartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6, the described bug is fixed!

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6. No problem with cursor behavior was found

Copy link
Contributor

@julian-wls julian-wls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6 during session. Didn't notice any cursor jump 👍

Copy link
Contributor

@PaRangger PaRangger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6, works now. 😄 The only thing i noticed is that if you click again on the "list" button while editing the list it now does not jump to the end of the list. I think that was the behaviour the previous code was trying to achieve, but I don't think its a important use case.

@github-actions github-actions bot added deployment-error Added by deployment workflows if an error occured and removed deploy:artemis-test3 labels Jan 21, 2025
@github-actions github-actions bot removed the deployment-error Added by deployment workflows if an error occured label Jan 21, 2025
@alekspetrov9e alekspetrov9e temporarily deployed to artemis-test4.artemis.cit.tum.de January 21, 2025 13:07 — with GitHub Actions Inactive
Copy link

@alekspetrov9e alekspetrov9e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem with the cursor.Tested on TS4

Copy link

@ItsaaaMeMario ItsaaaMeMario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS4, the cursor works correctly.

@krusche krusche merged commit 4c90b41 into develop Jan 21, 2025
111 of 117 checks passed
@krusche krusche deleted the bugfix/communication/fix-editing-formatted-list branch January 21, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) component:Communication ready to merge small tests
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

Text cursor jumps to end of line when editing text in a list
10 participants